<?php
//定义变量

if (!empty($_FILES)) {	
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'.date("Y-m-d",time()).'/';
	if( !is_dir($targetPath) )
        mkdir($targetPath);
	$pattern = '1234567890abcdefghijklmnopqrstuvwxyz
                ABCDEFGHIJKLOMNOPQRSTUVWXYZ,./&amp;l
                t;&gt;?;#:@~[]{}-_=+)(*&amp;^%$£"!';    //字符池
     $length = 8;
     $key = '2010';
	for($i=0;$i<=$length;$i++)
	{
		$key .= $pattern{mt_rand(0,35)};    //生成php随机数
	} 
	$ext = strtolower(substr(strrchr($_FILES['Filedata']['name'],'.'),1));
	$targetFile =  str_replace('//','/',$targetPath) . $key .'.'.$ext;

	// $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
	// $fileTypes  = str_replace(';','|',$fileTypes);
	// $typesArray = split('\|',$fileTypes);
	// $fileParts  = pathinfo($_FILES['Filedata']['name']);
	
	// if (in_array($fileParts['extension'],$typesArray)) {
		// Uncomment the following line if you want to make the directory if it doesn't exist
		// mkdir(str_replace('//','/',$targetPath), 0755, true);
		
		move_uploaded_file($tempFile,$targetFile);
		echo $_REQUEST['folder'] . '/'.date("Y-m-d",time()).'/'.$key .'.'.$ext;
	// } else {
	// 	echo 'Invalid file type.';
	// }
}
?>
